package com.cskaoyan.controller;



import com.cskaoyan.annotation.LogAnnotation;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.CommentReplyBO;
import com.cskaoyan.bean.bo.RefundBO;
import com.cskaoyan.bean.bo.ShipBO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.vo.adminOrder.*;
import com.cskaoyan.service.CommentService;
import com.cskaoyan.service.OrderService;
import com.cskaoyan.util.StringToArrayUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @RequestMapping("list")
    //public BaseRespVo list(Integer page,Integer limit,String sort,String order,String ordername) {
    public BaseRespVo list(BaseParam param, Integer[] orderStatusArray , Integer userId, String orderSn, @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")Date start ,@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")Date end) {
        OrderData orderData = orderService.query(param,orderStatusArray, userId, orderSn,start,end);
        System.out.println(orderService.selectOrderSnByOrderId(1));
        return BaseRespVo.ok(orderData);
    }
    @RequestMapping("detail")
    //public BaseRespVo list(Integer page,Integer limit,String sort,String order,String ordername) {
    public BaseRespVo detail(Integer id) {
        List<OrderGoods> orderGoodsList=orderService.queryOrderGoods(id);


        User user=orderService.OrderUser(id);
        //  System.out.println("以下是end");
        Order2 order=orderService.queryOrder(id);
        //System.out.println(end);

        OrderDetailData orderDetailData = new OrderDetailData(orderGoodsList,user,order);

        return BaseRespVo.ok(orderDetailData);
    }
    @RequestMapping("channel")
    //public BaseRespVo list(Integer page,Integer limit,String sort,String order,String ordername) {
    public BaseRespVo channel() {
        List<ChannelVO> channelVOs=new ArrayList<ChannelVO>();
        channelVOs.add(new ChannelVO("MD","慢慢来吧"));
        ChannelVO channelVO = new ChannelVO("YD","韵达速递");
        ChannelVO channelVO1 = new ChannelVO("ZD","中通速递");
        channelVOs.add(channelVO);
        channelVOs.add(channelVO1);


        return BaseRespVo.ok(channelVOs);
    }
    @LogAnnotation
    @RequestMapping("ship")
    //public BaseRespVo list(Integer page,Integer limit,String sort,String order,String ordername) {
    public BaseRespVo ship(@RequestBody ShipBO shipBO) {
       // System.out.println(shipChannel);
        orderService.updateShip(shipBO.getOrderId(),shipBO.getShipChannel(),shipBO.getShipSn());



        return BaseRespVo.ok(null);
    }
    @LogAnnotation
    @RequestMapping("refund")
    //public BaseRespVo list(Integer page,Integer limit,String sort,String order,String ordername) {
    public BaseRespVo refund(@RequestBody RefundBO refundBO) {
        // System.out.println(shipChannel);
        orderService.updateRefund(refundBO.getOrderId(),refundBO.getRefundMoney());
        return BaseRespVo.ok(null);
    }
    @LogAnnotation
    @RequestMapping("delete")
    //public BaseRespVo list(Integer page,Integer limit,String sort,String issue,String issuename) {
    public BaseRespVo delete(@RequestBody ShipBO shipBO) {
        orderService.update4delete (shipBO.getOrderId());


        return BaseRespVo.ok(null);
    }

    @Autowired
    CommentService commentService;
    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody CommentReplyBO commentReplyBO) {
        int reply = commentService.reply(commentReplyBO);
        if (reply == 1) {
            return BaseRespVo.invalidParameter("该评论已回复!");
        }
        return BaseRespVo.ok(null);
    }
}
